<template>
  <div class="login-container">
    <el-form ref="formRef" :model="form" label-width="80px" class="login-form">
      <div class="title-container">
        <h3 class="title">用户登录</h3>
      </div>
      <el-form-item>
        <el-icon :size="20" class="svg-container">
          <edit/>
        </el-icon>
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-icon :size="20" class="svg-container">
          <edit/>
        </el-icon>
        <el-input v-model="form.password" :type="pwdInputType"></el-input>
      </el-form-item>
      <el-button type="primary" @click="handleLogin">{{$t('login.loginBtn')}}</el-button>
      <el-button type="info" @click="changeType">{{ tips }}{{$t('login.pwdBtn')}}</el-button>
      <el-button type="success" @click="changeLanguage">变更语言</el-button>
      <router-link to="/">xxxxxx</router-link>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Edit } from '@element-plus/icons-vue'
import { login } from '@/api/login'
import { i18n } from '@/i18n'

const changeLanguage = () => {
  console.log('i18n.global.locale', i18n.global.locale)
  const lang = i18n.global.locale === 'en' ? 'zh' : 'en'
  localStorage.setItem('my_locale', lang)
  i18n.global.locale = lang
}
const pwdInputType = ref('password')
const tips = ref('显示')

const changeType = () => {
  if (pwdInputType.value === 'password') {
    pwdInputType.value = 'text'
    tips.value = '隐藏'
  } else {
    pwdInputType.value = 'password'
    tips.value = '显示'
  }
}

const form = ref({
  name: '',
  password: ''
})
const formRef = ref(null)
const handleLogin = () => {
  login(form.value)
}
</script>

<style lang="scss" scoped>

</style>
